package com.opennetexam.manager.mapper;

import com.opennetexam.manager.databasemodel.ExamAdminUser;
import com.opennetexam.manager.dto.ExamAdminInfoDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author naicha
 * Created on 2017/11/7.
 */
@Mapper
public interface ExamAdminUserMapper {

    @Insert("INSERT INTO examadminuser (\n" +
            "\tAccount,\n" +
            "\tManagerName,\n" +
            "\tPASSWORD,\n" +
            "\tUpdateTime\n" +
            ") SELECT\n" +
            "\t#{account},\n" +
            "\t#{managerName},\n" +
            "\t#{password},\n" +
            "\tNOW()\n" +
            "FROM\n" +
            "\tDUAL\n" +
            "WHERE\n" +
            "\tNOT EXISTS (\n" +
            "\t\tSELECT\n" +
            "\t\t\t1\n" +
            "\t\tFROM\n" +
            "\t\t\texamadminuser\n" +
            "\t\tWHERE\n" +
            "\t\t\tAccount = #{account}\n" +
            "\t)")
    Integer insert(ExamAdminUser adminUser);

    @Select("SELECT\n" +
            "\texamadminuser.*, relation.AppID,\n" +
            "\trelation.ExamSiteID\n" +
            "FROM\n" +
            "\texamadminuser\n" +
            "JOIN examaccountappsiterelation relation ON examadminuser.Account = relation.Account\n" +
            "WHERE\n" +
            "\texamadminuser.Account = #{account} LIMIT 1")
    ExamAdminInfoDTO getExamAdminUserByAccount(@Param(value = "account") String account);
}
